//准备开发服务器
const webpack = require('webpack')
const config = require('./webpack.config.js')
const Server = require('./webpack-dev-server/lib/Server.js');
function startDevServer(complier,config) {
    // console.log(complier, 'complier')
    // console.log(config, 'config')
    const devServerArgs = config.devServer || {};
    //启动http服务 里面有负责打包项目的并提供预览服务，通过它访问打包后的文件
    const server = new Server(complier,devServerArgs)
    const {port = 9000, host="localhost"}  = devServerArgs
    server.listen(port,host,(err)=>{
        console.log(`Project is running at http://${host}:${port}`)
    })
}
//2、创建webpack实例
const complier =  webpack(config)
//3、启动服务http服务器
startDevServer(complier,config)
module.exports = startDevServer